|
|
|
|
|
|
|
Tip If given the choice, you should probably choose the cmdDone naming convention. The word OK, which is not a verb, is sometimes ambiguous because it doesn't indicate a business process being complete. The word Done is a verb, and it definitely clues the user to the completion of a task. In general, command buttons should have names in verb form indicating some action or event. |
|
|
|
|
|
|
|
|
|
The undo operation would be similar to that of the Cancel button, except it is appropriate for most forms. That is, everywhere a user can enter information and submit that information in a transaction for processing, you should have an Undo button. An undo operation requires |
|
|
|
|
|
|
|
|
Cancellation of a transaction |
|
|
|
|
|
|
|
|
Repopulation of previous data into display controls such as text boxes, labels, combo and list boxes, and grids |
|
|
|
|
|
|
|
|
For the transaction cancellation, invoke the clickedCancelBtn method. For the restoring of displayed information, you need some mechanism for keeping the previous data without ruining the encapsulation of the business/domain classes from which the information came. The Memento design pattern is good for this. |
|
|
|
|
|
|
|
|
A Memento class has two methods, getState and setState. These methods are used to save (set) the state of a business class before new data is entered by the user and to restore (get) that state in the event the user cancels the transaction. The business class instance creates the Mementotypically in a createMemento() methodand passes it to a Caretaker object. In the case of forms, the Caretaker is the form's controller. For your purposes, the controller is named FormController. |
|
|
|
|
|
|
|
|
To be a proper caretaker, FormController needs two methods, clickedModifyBtn() and clickedUndoBtn(), and a property, theBusinessMemento. Listing 11.4 shows the two methods. |
|
|
|
|
|
|
|
|
LISTING 11.4. THEclickedModifyBtnANDclickedUndoBtnMETHODS CARRY OUT THE UNDO RESPONSIBILITIES OFFormControllerON BEHALF OF ITS FORM. |
|
|
|
 |
|
|
|
|
1: Public Sub clickedModifyBtn()
2: Set theBusinessMemento = theBusiness.createMemento
3: theBusiness.MyName = Samsona Software
4: theForm.Text1 = theBusiness.MyName
5: End Sub
6:
|
|
|
|
|
|